package com.itheima.core.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.itheima.core.pojo.product.Sku;
import com.itheima.core.service.product.SkuService;

/**
 * @author zhang.cheng
 *
 *         2017年3月7日
 */
@Controller
public class SkuController {

	@Autowired
	private SkuService skuService;

	@RequestMapping(value = "/sku/list.do")
	public String toSkuList(Long productId, Model model) {

		List<Sku> skuList = skuService.selectSkuList(productId);
		model.addAttribute("skuList", skuList);

		return "sku/list";
	}

	@RequestMapping(value = "/sku/updateSku.do")
	public void updateSku(Sku sku, HttpServletResponse response) throws Exception {
		skuService.updateSku(sku);
		JSONObject jo = new JSONObject();
		jo.put("message","保存成功" );
		response.setContentType("application/json;charset=UTF-8");
		response.getWriter().write(jo.toString());
	}
}
